
import { RouteRecordRaw } from "vue-router"
// import router from "../router"
//  const routerRole = (arr: Array<RouteRecordRaw>, router: any, parentName?:string) => {
//     console.log(arr,router);
//     arr.forEach( item => {
//         parentName && router.addRoute(parentName, item)
//         !parentName && router.addRoute(item)
//     })
//     console.log(router);
    
//     // router.options.routes.push(...arr)
// }
 const routerRole = (arr: Array<RouteRecordRaw>, router: Array<RouteRecordRaw>, parentName?:string) => {
    if (parentName) {
            router[0].children && routerFind(arr,router[0].children,parentName)
} else {
    router.push(...arr)
}
// console.log(parentName);

// router.options.routes.push(...arr)
}
const routerTree = (arr:Array<RouteRecordRaw>, router: any, parentName?:string) => {
    let bool = false
    if (!parentName) {
        router.options.routes.push(arr)
    } else {
        !bool && router.options.routes[0]
    }
}

const routerFind= (arr: Array<RouteRecordRaw>,router:  Array<RouteRecordRaw>,name: string) => {
        for (let i = 0; i < router.length; i++) {
            if (router[i].name === name) {
                router[i].children?.push(...arr)
            } else {
            }
    }
}

export { routerRole, routerTree }